﻿'========================================================================
'功能:申請種類
'作者:andy
'日期: 2011/3/1
'========================================================================
Partial Class WebForm_Manage_ApplyTypeMaintain
    Inherits BasePage
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = ActualUID
            hiDBName.Value = dbName
            If Not ChkProgramRight(1) Then '查詢
                btnInsert.Visible = False
                gvTelType.Visible = False
            End If
            If Not ChkProgramRight(2) Then '新增
                btnInsert.Visible = False
            End If

          
            If Not ChkProgramRight(2) Then '編輯
                gvTelType.Columns(0).Visible = False
            End If


        End If

    End Sub

   
   
    Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        hiKind.Value = "Insert"
        gvTelType.EditIndex = 0
        gvTelType.PageIndex = 0
        gvTelType.DataBind()

    End Sub

    Protected Sub gvTelType_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvTelType.RowCancelingEdit
        gvTelType.EditIndex = -1
        hiKind.Value = ""
    End Sub

    Protected Sub gvTelType_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles gvTelType.RowUpdated
        gvTelType.EditIndex = -1
        hiKind.Value = ""
    End Sub

    Protected Sub ddlsuit_site_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlsuit_site.SelectedIndexChanged
        hiKind.Value = ""
        gvTelType.EditIndex = -1
        gvTelType.DataBind()
    End Sub

    Protected Sub gvTelType_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvTelType.RowUpdating

        Dim type_code As String = CType(gvTelType.Rows(e.RowIndex).FindControl("txttype_code"), TextBox).Text.Trim
        Dim type_name As String = CType(gvTelType.Rows(e.RowIndex).FindControl("txttype_name"), TextBox).Text.Trim
        Dim approveLevel As Integer
        Try
            approveLevel = Integer.Parse(CType(gvTelType.Rows(e.RowIndex).FindControl("txtNeedApprove"), TextBox).Text.Trim)
        Catch ex As Exception
            ShowMessageForAjax(btnInsert,GetLocalResourceObject ("NeedApproveError"))
            e.Cancel = True
            Exit Sub
        End Try
        If approveLevel < 0 Or approveLevel > 6 Then
            ShowMessageForAjax(btnInsert, GetLocalResourceObject("NeedApproveError"))
            e.Cancel = True
            Exit Sub
        End If


        If (type_code = "") Then
            e.Cancel = True
            ShowMessageForAjax(btnInsert, GetLocalResourceObject("ErrEmpty"))
            Exit Sub
        End If
        If (type_name = "") Then
            e.Cancel = True
            ShowMessageForAjax(btnInsert, GetLocalResourceObject("ErrEmptytype_name"))
            Exit Sub
        End If
        Dim bbl As Telecom.BBL.TelTypeBBL = New Telecom.BBL.TelTypeBBL()
        If CType(gvTelType.Rows(e.RowIndex).FindControl("txttype_code"), TextBox).Enabled Then
            If bbl.type_codeIsExist(dbName, ddlsuit_site.SelectedValue, type_code) Then
                e.Cancel = True
                ShowMessageForAjax(btnInsert, GetLocalResourceObject("ErrExist"))
                Exit Sub
            End If
        End If


    End Sub
End Class
